package com.mlnx.web.data.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mlnx.common.entity.Response;
import com.mlnx.common.entity.ResponseData;
import com.mlnx.common.form.PageForm;
import com.mlnx.external.push.form.PushRecordForm;
import com.mlnx.external.push.service.PushDetailService;
import com.mlnx.external.push.service.PushRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.shan.spring.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api(value = "推送记录接口",tags={"推送记录接口"})
@RestController
@RequestMapping("push/record")
public class PushRecordController extends BaseController {

    @Autowired
    private PushRecordService pushRecordService;

    @Autowired
    private PushDetailService pushDetailService;


    @ApiOperation("删除推送与设备关系数据")
    @RequestMapping(value = "", method = {RequestMethod.DELETE})
    public Response deleteRelation( @RequestParam(value = "ids", required = true) List<Integer> ids) {
        pushRecordService.removeByIds(ids);
        return result();

    }

    @ApiOperation("分页获取所有关系数据")
    @GetMapping(value = "")
    public ResponseData listPage(@Valid PageForm pageForm ,@Valid PushRecordForm pushRecordForm) {


        return result(pushRecordService.listPage(pageForm,pushRecordForm));
    }

    @ApiOperation("根据记录ID分页获取推送的详情")
    @GetMapping(value = "detail")
    public ResponseData listPage(@Valid PageForm pageForm, @RequestParam Integer id) {
        QueryWrapper queryWrapper =new QueryWrapper();
        queryWrapper.eq("record_id",id);
        return result(pushDetailService.page(new Page<>(pageForm.getCurrent(),pageForm.getSize()),queryWrapper));
    }

    @ApiOperation("重试")
    @GetMapping(value = "retry")
    public Response retry(@RequestParam Integer id) {
        pushRecordService.retry(id);
        return result();
    }


}
